<include file="Inc/html_header" />
<div>
    <form method="post" action="" enctype="multipart/form-data">
        <input type="hidden" name="id" value="<?php echo $config['config_id'];?>" />
        <table class="table table-bordered table-hover">
            <thead>
                <tr>
                    <th colspan="2"><?php echo ($action == 'add') ? '添加' : '修改';?>配置</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td width="100" class="tdf">变量名称 *：</td>
                    <td><input class="form-control form-focus input_text" type="text" name="name" id="name"  size="30" maxlength="40" value="<?php if($action == 'edit'){ echo $config['name'];}?>" <?php if($action == 'edit'){ echo 'readonly';}?> /></td>
                </tr>
                <tr>
                    <td class="tdf">变量显示 *：</td>
                    <td><input class="form-control form-focus input_text" type="text" name="title" msg="请填写变量显示" class="required" size="30" maxlength="80" value="<?php if($action == 'edit'){ echo $config['title'];}?>" /></td>
                </tr>
                <tr>
                    <td class="tdf">变量类型：</td>
                    <td class="mySelect">
                        <select name="type" onchange="showOptions(this.value)">
                            <?php foreach($searchOptions['typeOptions'] as $title){ ?>
                                <option value="<?php echo $title['type']; ?>"  <?php if($title['type'] == $config['type']){ echo 'selected="selected"'; } ?>><?php echo $title['val'];?></option>
                            <?php } ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="tdf">隶属分类：</td>
                    <td class="mySelect">
                        <select name="parent_id">
                            <?php foreach($searchOptions['catOptions'] as $title){ ?>
                                <option value="<?php echo $title['config_id']; ?>" <?php if($title['config_id'] == $config['parent_id']){ echo 'selected="selected"'; } ?>><?php echo $title['title'];?></option>
                            <?php } ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="tdf">变量选项：</td>
                    <td>
                        <div id="options" <?php if( ! in_array($config['type'], array('radio', 'checkbox', 'select'))){ echo 'style="display:none;"'; }?>>
                            <div id="type_options">
                                <?php if( ! empty($config['type_options'])){ foreach($config['type_options'] as $name=>$title){ ?>
                                    <p><a onclick="addOption(this)" href="javascript:;"><i class="icon-plus-sign"></i></a> 值
                                        <input type="text" name="type_key[]" size="20" value="<?php echo $name;?>" class="form-control form-focus input_text" />
                                        显示文字 <input type="text" name="type_value[]" size="20" value="<?php echo $title;?>" class="form-control form-focus input_text" />
                                    </p>
                                <?php }}else{ ?>
                                    <p><a onclick="addOption(this)" href="javascript:;"><i class="icon-plus-sign"></i></a> 值
                                        <input type="text" name="type_key[]" size="20" class="form-control form-focus input_text" />
                                        显示文字 <input type="text" name="type_value[]" size="20" class="form-control form-focus input_text" />
                                    </p>
                                <?php } ?>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="tdf">变量说明：</td>
                    <td><textarea name="notice" class="form-control form-focus input_text" style="width:320px; height:70px;"><?php echo $config['notice'];?></textarea></td>
                </tr>
                <tr>
                    <td class="tdf">&nbsp;</td>
                    <td>
                        <input type="submit" value="<?php echo ($action == 'add') ? '添加' : '修改';?>" class="btn btn-primary" />
                        <input type="button" value="返回" class="btn" onclick="backStep();" />
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
</div>
<script type="text/javascript">
    function showOptions(type)
    {
        var opt = document.getElementById("options");
        if (type == 'radio' || type == 'checkbox' || type == 'select') {
            opt.style.display = '';
        } else {
            opt.style.display = 'none';
        }
    }
    function addOption(obj)
    {
        var opt = document.getElementById("type_options");
        var p = document.createElement("p");
        p.innerHTML = obj.parentNode.innerHTML.replace(/(.*)(addOption)(.*)(\-)(plus-sign)/i, "$1removeOption$3$4remove");
        opt.appendChild(p);
    }
    function removeOption(obj)
    {
        var opt = document.getElementById("type_options");
        opt.removeChild(obj.parentNode);
    }
</script>
<include file="Inc/html_footer" />